/**
 * @brief UDP协议
 * @version 1.0
 * @author 宋炜
 * @date 2023-08-25
 */

#pragma once
#include <string>
#include <atomic>
#include <mutex>
#include <thread>

#include "mallocSharedPtr.hpp"
#include "dataCh.hpp"

class udp : public dataCh
{
public:
	struct stMsg{
		mandaravaIP_addr  addr;
		wheels::mallocSharedPtr< char >   buff;
	}
private:
	std::atomic< int >    m_fd__;
public:
	udp( const std::string& addr , int port , bool bind = false );
	virtual ~udp();

	void send( const std::string& daddr , uint16_t dport , const char * data , size_t len );
	void send( const std::string& addr , uint16_t dport , wheels::mallocSharedPtr<char >& buff );

	virtual void onReadyRead( const char * data = nullptr , size_t len )  final;
	virtual nativeH_t native_handle() final;
};
